/**
 * Foxit Software Inc.
 * Copyright(C) 2005-2014, all rights reserved.
 * The following code is copyrighted and contains proprietary information
 * and trade secrets of Foxit Software Inc.

 * Description: 通用的markup annotation处理器，非annotation编辑模式使用
 * Author: shaojie zhuo
 */

define(function (require, exports, module) {
    WebPDF.CommonMarkupHandler = "CommonMarkupHandler";
    WebPDF.InkHandler = "Ink";

    /**
     * @param readerApp
     * @param name
     * @param pCommentAnnotPlugin
     * @constructor
     * @extends WebPDF.IBA_AnnotHandler
     */
    WebPDF.CommonMarkupAnnotHandler = function (readerApp, annotHandlerManager,type) {
        this.readerApp = readerApp;
        this.type = type;
        this.annotHandlerManager = annotHandlerManager;
    };

    WebPDF.CommonMarkupAnnotHandler.prototype =
    {
        getType: function () { return this.type; },

        canAnswer: function (annot, bAllowSelectTextTool)
        {
            var type = annot.getSubType();
            var tool = this.readerApp.getCurToolHandler();
            if (tool){
                var toolName = tool.getName();
                if (toolName===WebPDF.Tools.BA_SELANNOT_TOOLNAME || toolName === WebPDF.Tools.TOOL_NAME_HAND ||
                    toolName === this.annotType){
                    return true;
                }
                if (bAllowSelectTextTool != undefined && bAllowSelectTextTool) {
                    if (toolName === WebPDF.TOOL_NAME_SELECTTEXT) {
                        return true;
                    }
                }
            }
            return false;
        },
        canMove: function (subType) {
            return false;
        },
        moveAnnot: function(pageView, selectedAnnot,
                            offsetX, offsetY ,newPosX, newPosY){
        },
        deleteAnnot: function(pageView, annot){
            var annotName = annot.getAnnotName();
            var annotUIManager = this.annotHandlerManager.getUIManager();
            var annotDivID = annotUIManager.getAnnotDivID(pageView, annotName);
            $("#" + annotDivID).remove();
            var annotShowDivID = annotUIManager.getInkAnnotDivID(pageView, annotName);
            $("#" + annotShowDivID).remove();
        },
        onDraw: function(pageView, selectedAnnot, isRedraw, extraScale){
        },
        onSelected: function(pageView, annot){
            var annotName = annot.getAnnotName();
            var annotUIManager = this.annotHandlerManager.getUIManager();
            var annotDivID = annotUIManager.getAnnotDivID(pageView, annotName);
            $("#" + annotDivID).addClass("fwr-annot-selected");
            /*$(".fwr_annot_selected").jeegoocontext(_MenuID, {
             onSelect: function (e, context) { return _self.OnSelect($(this)); }
             });*/
            return true;
        },
        onDeSelected: function(pageView, annot){
            var annotName = annot.getAnnotName();
            var annotUIManager = this.annotHandlerManager.getUIManager();
            var annotDivID = annotUIManager.getAnnotDivID(pageView, annotName);
            $("#" + annotDivID).removeClass("fwr-annot-selected");
        },
        onFocus: function(pageView, annot){
            this.annotHandlerManager.getMarkupAnnotHandler().onFocus(pageView, annot);
        },
        onLButtonDown: function(pageView,annot, event){
        	return this.onSelected(pageView,annot);
        },
        onLButtonUp: function(pageView,annot, event){

        },
        onLButtonDblClk: function(pageView, annot, event){
            this.annotHandlerManager.getMarkupAnnotHandler().onLButtonDblClk(pageView, annot,event);
        },
        onMouseOver: function(pageView, annot, event){
            this.annotHandlerManager.getMarkupAnnotHandler().onMouseOver(pageView, annot,event);
        },
        onMouseLeave : function (pageView, annot, event) {
            this.annotHandlerManager.getMarkupAnnotHandler().onMouseLeave(pageView, annot,event);
        },
        onUpdatePosition: function(pageView, annot, visibleRect){
            var pdfPage = pageView.getPDFPage();
            var annotPDFRect = annot.getRect();
            var annotDocRect = pageView.pdfToDoc(annotPDFRect, true);
            var annotUIManager = this.annotHandlerManager.getUIManager();
            var annotDivID = annotUIManager.getAnnotDivID(pageView, annot.getAnnotName());
            $("#" + annotDivID).css({
                    left: annotDocRect.left,
                    top: annotDocRect.top,
                    width: WebPDF.RectUtils.width(annotDocRect),
                    height: WebPDF.RectUtils.height(annotDocRect)
            });
        }
    };



    return WebPDF.CommonMarkupAnnotHandler;
});